﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GIMS.MODEL;
using KPIS.GERP.GIMS.IDAL;

namespace KPIS.GERP.GIMS.DAL
{
    public sealed class PersonalDAL : IDALPersonal
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public PersonalDAL()
        {

        }

        public string[] GetUserJobSite(int emp_seq)
        {
            string strSQL;
            string[] strResult = new string[2];
            DataSet ds;
            try
            {
                dbManager.Open();
                dbManager.BeginTransaction();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@emp_seq", emp_seq);

                //strSQL = "SELECT CAST(CONCAT(wa.SCOPE_SEQ, '-', js.JOB_SITE_SEQ) AS CHAR) AS VALUE"
                strSQL = "SELECT js.JOB_SITE_SEQ"
                        + ", js.JOB_SITE_NAME"
                    + " FROM HRM_PS_EMPLOYEES em"
                        + " INNER JOIN HRM_MP_JOB_SITES js ON em.WORKING_JOB_SITE_SEQ = js.JOB_SITE_SEQ"
                        + " INNER JOIN HRM_MP_WORK_AREAS wa ON js.WORK_AREA_SEQ = wa.WORK_AREA_SEQ" 
                        + " INNER JOIN HRM_MP_SCOPES ms ON wa.SCOPE_SEQ = ms.SCOPE_SEQ" 
                    + " WHERE em.EMP_SEQ = @emp_seq";

                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    strResult[0] = Convert.ToString(ds.Tables[0].Rows[0][0]);
                    strResult[1] = Convert.ToString(ds.Tables[0].Rows[0][1]);
                }

                dbManager.CommitTransaction();
            }
            catch (Exception ex)
            {
                dbManager.RollBackTransaction();
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
            
            return strResult;
        }
    }
}
